function toApurchase($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q, fileListService,backlogPersonList) {
    $$scope = $scope;
    // $$scope.applyInfo = {};
    $CertusFormAjax = CertusFormAjax;
    $CertusJsonAjax = CertusJsonAjax;
    $fileListService = fileListService;
    $backlogPersonList = backlogPersonList;

    purchaseGrid.load();

    // 资产库借货记录
    productSelectDatagrid = $CertusJsonAjax.dataInit("findAssetsList", {
        code: 9,
        param: "NaN",
        addr: "NaN"
    }, lidColumns, 'lidContainer', 'lidToolBarContainer', 5, [10]);

    $$scope.searchProduct = function () {
        ;
        productSelectDatagrid.parameters = {
            code: 9,
            param: $$scope.select.productType,
            addr: $$scope.select.addr
        };
        productSelectDatagrid.refresh(true);
    }

    $$scope.select = {};

    $$scope.select.applyForSelect = [{
        name: "商用",
        code: "SY"
    },
        {
            name: "自用",
            code: "ZY"
        },
        {
            name: "其他",
            code: "QT"
        }
    ]

    $$scope.select.affiliationSelect = [{
        name: "南京",
        code: "STSNJ"
    },
        {
            name: "北京",
            code: "STSBJ"
        },
        {
            name: "广州",
            code: "STSGD"
        },
        {
            name: "上海",
            code: "STSSH"
        }
    ]

    $$scope.select.bigClassSelect = [{
        name: "设备",
        code: "SB"
    },
        {
            name: "服务",
            code: "FW"
        },
        {
            name: "其他",
            code: "QT"
        }
    ]


    $$scope.sbchanged = function (a) {
        if (a == "SB") {
            $$scope.sbshow = true;
            $$scope.sbbushow = false;
        } else {
            $$scope.sbshow = false;
            $$scope.sbbushow = true;
            $$scope.applyItem.commodityCateName = "服务";
            $$scope.applyItem.commodityClassName = "服务";
        }
    }


    $CertusJsonAjax.ajax("purchaseProductCode", {}, function (res) {
        if (res.data) {
            var cate = res.data.cate;
            var clas = res.data.clas;

            $$scope.select.cateCodeSelect = new Array();
            for (var i in cate) {
                var split = cate[i].split(",");
                $$scope.select.cateCodeSelect.push({
                    code: split[0],
                    name: split[1]
                })
            }

            $$scope.select.classCodeSelect = new Array();
            for (var i in clas) {
                var classs = clas[i].split(",");
                if (classSet[classs[0]]) {
                    classSet[classs[0]].push({
                        code: classs[1],
                        name: classs[2]
                    });
                } else {
                    classSet[classs[0]] = new Array();
                    classSet[classs[0]].push({
                        code: classs[1],
                        name: classs[2]
                    });
                }
                $$scope.select.classCodeSelect = {};
            }
        }
    })

    $$scope.cateChange = function (cateCode) {
        $$scope.select.classCodeSelect = classSet[cateCode];
    }

    $CertusFormAjax.ajax("findStyles", {}, function (response) {
        $$scope.select.assetClassSelect = response.data;
    });

//资产转移申请 提交
    $$scope.applyItemSubmit = function () {
        if (certusValidateNotnullPolyfill()) {
            var cateCodeSelect = $$scope.select.cateCodeSelect;
            var classCodeSelect = $$scope.select.classCodeSelect;

            for (var i in cateCodeSelect) {
                if (cateCodeSelect[i].code == $$scope.applyItem.commodityCateCode) {
                    $$scope.applyItem.commodityCateName = cateCodeSelect[i].name;
                }
            }
            for (var j in classCodeSelect) {
                if (classCodeSelect[j].code == $$scope.applyItem.commodityClassCode) {
                    $$scope.applyItem.commodityClassName = classCodeSelect[j].name;
                }
            }

            if ($$scope.applyItem.id) {
                purchaseId = $$scope.applyItem.id;
                purchaseProductDatas = purchaseProductDatas.filter(isSamePurchase);
            } else {
                $$scope.applyItem.id = (new Date()).getTime() + Math.floor(Math.random() * 10);
            }
            purchaseProductDatas.push($$scope.applyItem);
            purchaseGrid.exhibitDatas = purchaseProductDatas;
            purchaseGrid.refresh(false);
            $$scope.applyItem = {};
            $('.shadbox').hide();
        }
    }

    var fileInstantiation = {
        classCateCode: 'WBLY',
        fileClassCode: 'KHBJD'
    }
    var fileInstantiationDisable = {
        classCateCodeDis: true, //文件类目不可修改
        fileClassCodeDis: true //文件类型不可修改
    }

    $$scope.getsssbbb = function(bb){
        ;
        //starting denied sentback others completed
        if(bb == "starting"){
            return "正在进行中";
        }else if(bb == "denied"){
            return "否决";
        }else if(bb == "sentback"){
            return "被退";
        }else if(bb == "others"){
            return "关闭";
        }else if(bb == "completed"){
            return "完成";    }else if(bb == "terminated"){        return "终结";    }    else if(bb == "cancelled"){        return "通过";}
        return "待办";
    }

//调用初始化方法
    initFileUpload($$scope, fileInstantiation, fileInstantiationDisable, $CertusFormAjax);

    $$scope.addFileBuy = function () {
        fileUpload($$scope, function (res) {
            if (res.data) {
                if ($$scope.applyInfo) {
                    var da = {
                        "fileId": res.data,
                        "fileName": $$scope.file.fileName,
                        "createTime": new Date()
                    }
                    if ($$scope.applyInfo.attachmentFiles) {

                    } else {
                        $$scope.applyInfo.attachmentFiles = new Array();
                    }
                    $$scope.applyInfo.attachmentFiles.push(da);
                    $(".shuplod").hide();
                    return;
                }
            }
            layer.msg("文件上传失败");
        }, null, $CertusFormAjax);
    }

    //请购单 申请 提交
    $$scope.submmitPurchase = function () {
        //判断项目 id 是否 存在
        ;
        var num = isNaN(parseInt($$scope.applyInfo.projId));
        if (num) {
            layer.msg("项目没有找到，请检查");
            return;
        }
        if (certusValidateNotnull()) {
            $CertusJsonAjax.ajax("firstApplyItem", {
                projId: parseInt($$scope.applyInfo.projId),
                buyingRequisitionEntity: $$scope.applyInfo,
                purchaseItems: purchaseGrid.exhibitDatas,
                productApplyItems: library1Grid.exhibitDatas
            }, function (res) {
                if (res.data) {
                    if (res.data == "success") {
                        findBacklogPersonHead($CertusFormAjax, "QMQGLC");
                        window.history.back();
                    }
                }
                layer.msg(res.data);
            })
        }

    }
}

function toDataGridPurchase($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q, fileListService) {
    $$scope = $scope;
    $$scope.applyInfo = {};
    $CertusFormAjax = CertusFormAjax;
    $CertusJsonAjax = CertusJsonAjax;
    $fileListService = fileListService;

    var dataInitProjName = $CertusJsonAjax.dataInit('purchaseListDis', null, listColumns, 'listContainer', 'listToolBarContainer');

    $$scope.searchByProjName = function () {
        ;
        dataInitProjName.parameters = {
            projName: $("#purchaseInputProj").val()
        }
        dataInitProjName.refresh(true);
    }
}

function toPurchaseBacklog($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q, fileListService) {
    $$scope = $scope;
    ;
    $CertusFormAjax = CertusFormAjax;
    $CertusJsonAjax = CertusJsonAjax;
    $fileListService = fileListService;

    var nowBrCode = $routeParams.nowBrCode;

    $$scope.applyInfo = {};
    // purchaseStepEntity = {
    //     "processInstanceId": $CertusJsonAjax.getProInstanceId()
    // }
    $$scope.submitter = {};
    $$scope.submmitData = {};
    // $$scope.submmitData.purchaseStepEntity = {
    //     "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    //     "stepInstanceId": $CertusJsonAjax.getStepInstanceId(),
    // }
    $$scope.select = {};
    $$scope.disUploadPurchaseFile = function () {
        $$scope.modalContent = {};

        $$scope.modalContent = eval($$scope.headerMap.attachmentFilestr);

        // $$scope.modalContent = data.data;
        $$scope.ok = function () {
            $modalInstance.close(); // 点击确认后关闭弹窗
        };
        $$scope.cancel = function () {
            $modalInstance.dismiss('cancel'); // 点击取消后撤销模态框
        }
        var modalContent = $$scope.modalContent;

        $fileListService.openConfirmWindow("提示", modalContent).then(function (res) {
        });
    }

    $$scope.getsssbbb = function (bb) {
        ;
        //starting denied sentback others completed
        if (bb == "starting") {
            return "正在进行中";
        } else if (bb == "denied") {
            return "否决";
        } else if (bb == "sentback") {
            return "被退";
        } else if (bb == "others") {
            return "关闭";
        }else if(bb == "completed"){
            return "完成";    }else if(bb == "terminated"){        return "终结";    }    else if(bb == "cancelled"){        return "通过";}
        return "待办";
    }

    $CertusFormAjax.ajax("queryByBrcode", {
        "brCode": nowBrCode
    }, function (res) {
        if (res.data) {
            $$scope.headerMap = res.data.headerMap;
            $$scope.processs = res.data.processs;
            brCode = res.data.headerMap.brCode;
            // purchaseStepEntity.buyingRequisitionCode = res.data.headerMap.brCode;
            $$scope.submmitData.purchaseStepEntity = {};
            $$scope.submmitData.purchaseStepEntity.buyingRequisitionCode = res.data.headerMap.brCode;
            $$scope.submmitData.purchaseStepEntity.projId = res.data.headerMap.projId;
            var datas = res.data.buyings;
            $$scope.buyings = res.data.buyings;
            var priceOption1 = {
                lang: 'zh-cn',
                ajaxLoad: false,
                // loadURL:'url',
                exportFileName: '采购单条目信息',
                datas: datas,
                columns: proc1Columns,
                extraWidth: 20,
                gridContainer: 'purchaselogContainer',
            };
            aboveGrid = $.fn.dlshouwen.grid.init(priceOption1);
            aboveGrid.load();

            //初始化 报价 文件 数据
            if (datas) {
                for (var i in datas) {
                    if (datas[i].biCode) {
                        bqArray[datas[i].biCode] = datas[i].buyingQuoteItemEntities;
                    }
                }
                //初始化 历史报价 文件 数据
                for (var i in datas) {
                    if (datas[i].biCode) {
                        oldBqArray[datas[i].biCode] = datas[i].inventorQuoteItemEntities;
                    }
                }
            }

            var prcListOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                // loadURL:'url',
                exportFileName: '资产信息',
                datas: res.data.inventors,
                columns: prcListColumns,
                gridContainer: 'assetslogContainer',
                tools: '',
                pageSize: 10,
                extraWidth: 20,
                pageSizeLimit: [10, 15, 20]
            };
            belowGrid = $.fn.dlshouwen.grid.init(prcListOption);
            belowGrid.load();

            var endOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                // loadURL:'url',
                exportFileName: '结果清单',
                datas: [],
                columns: endColumns,
                gridContainer: 'endContainer',
                // toolbarContainer: 'endToolBarContainer',
                tools: '',
                pageSize: 10,
                extraWidth: 20,
                pageSizeLimit: [10, 15, 20]
            };
            endGrid = $.fn.dlshouwen.grid.init(endOption);
            endGrid.load();
        }
    });

}